/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Curriculums;

/**
 *
 * @author Cesar
 */
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class Titulos {
    static String bd = "bitacoraelectronica";
    static String login = "root";
    static String password = "A74543";
    static String url = "jdbc:mysql://localhost/"+bd;
    
    private Object[] titulos;
    private Object[] universidad;
    
    Connection conn = null;
            
    public Titulos(){
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            conn = DriverManager.getConnection(url,login,password);
            if (conn != null) {
                System.out.println("Conexión a base de datos "+url+" ... Ok");
            }
        }
        catch (Exception e) {
                System.out.println(e);
                System.exit(0);
        } 
    }
    
    
    public void getTitulos(String prof){
        List<String> list = new ArrayList<String>();
        List<String> list2 = new ArrayList<String>();
        try{
            Statement s = conn.createStatement();
            ResultSet rs = s.executeQuery("select * from Titulo"
                    + " where UsernameProf = '"+prof+"'");
            while (rs.next())
            {
                list.add( rs.getString("Titulo"));
                list2.add( rs.getString("Universidad"));
            }
        }
        catch (Exception e) {
                System.out.println(e);
                System.exit(0);
        }
        titulos =  list.toArray();
        universidad = list2.toArray();
    }
    
    public Object[] getTiulos(){
        return titulos;
    }
    public Object[] getUniversidades(){
        return universidad;
    }
    
    public void insertarTitulo(String usuario, String tit, String univ){
        try{
            Statement s = conn.createStatement();
            s.executeUpdate("INSERT INTO titulo VALUES ('"+usuario+"','"+tit+"','"+univ+"')" );
        }
        catch (Exception e) {
            System.out.println(e);
            System.exit(0);
        }
    }
    
    public void EliminarTitulos(String usuario){
        try{
            Statement s = conn.createStatement();
            s.executeUpdate("Delete From titulo where usernameProf = '"+usuario+"'");
           
        }
        catch (Exception e) {
            System.out.println(e);
            System.exit(0);
        }
    }
}
